<?php
/**
 * 用户组模型
 * @author Administrator
 *
 */
class  System_group_model extends MY_Model{
	function __construct()
	{
		parent::__construct();
	}
	
	function get_table_data($data)
	{
        // 当前页码
        $offset = $data['offset'];
        $this->success['total'] = $this->db->from("system_group")
        ->count_all_results('', false); //查询总数
        $this->success['data'] = $this->db->select()
        ->limit($this->limit, $offset * $this->limit)
        ->get()->result_array();
        return $this->success;
    }
	
	
	/**
	 * 添加和编辑方法
	 * @param unknown $data 添加和编辑数据 数组
	 * @return unknown success：1000 param_error：1001
	 */
	function replace_system_group($data)
	{
		if(!empty($data)){
			if(isset($data['id'])&&!empty($data['id'])){//修改方法
				$this->db->where('id', $data['id']);
				$this->db->update("system_group",$data);
				return $this->success;
			}else{//添加方法
				$data['create_time']=time();
				$this->db->insert('system_group',$data);
				return $this->success;
			}
		}else{
			return $this->param_error;//返回参数错误
		}
	}
	/**
	 * 验证用户组
	 * @param unknown $group_name
	 */
	function verify_group_name($group_name){
	    if(!empty($group_name)){
            $this->db->where('system_group.group_name',trim($group_name));
            $num=$this->db->get('system_group')->num_rows();
            if($num>0){
                $this->success['data']=0;
            }else{
                $this->success['data']=1;
            }
            return $this->success;
        }else{
	        return $this->param_error;//返回参数错误
	    }
	}
	
	/**
	 * 查询全部用户组
	 */
	function get_system_group_all()
	{
	    $this->db->where('status', 1);
	    $this->success['data'] = $this->db->select("system_group.id,system_group.group_name")
	    ->from("system_group")
	    ->get()
	    ->result_array();
	    return $this->success;//返回查询数据
	}
}